/*
 * Copyright (C) 2009 aileron.cc
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package cc.aileron.anime;

import java.awt.Color;
import java.awt.Dimension;

import javax.media.Manager;
import javax.media.MediaLocator;
import javax.media.Player;
import javax.media.control.FrameGrabbingControl;
import javax.swing.JFrame;

import wiiusej.WiiUseApiManager;
import wiiusej.Wiimote;

/**
 * @author Aileron
 * 
 */
public class ApplicationContext
{
    /**
     * @throws Exception
     */
    public ApplicationContext() throws Exception
    {
        // main-frame
        this.mainFrame = new JFrame("stop-montion-animation");
        this.mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.mainFrame.setSize(dimension);
        this.mainFrame.setBackground(Color.BLACK);
        this.mainFrame.setResizable(false);

        // camera
        this.cameraPlayer = Manager.createRealizedPlayer(new MediaLocator(
                "vfw://0"));
        this.cameraPlayer.getVisualComponent()
            .setBackground(Color.BLACK);
        this.mainFrame.getContentPane()
            .add(this.cameraPlayer.getVisualComponent());
        this.grabbingControl = (FrameGrabbingControl) cameraPlayer.getControl(FrameGrabbingControl.class.getName());
        this.cameraPlayer.start();

        final Wiimote[] wiimotes = WiiUseApiManager.getWiimotes(1, true);
        if (wiimotes.length == 0)
        {
            throw new Error("not rimotes");
        }

        // wii
        this.wiimote = wiimotes[0];
        this.wiimote.activateMotionSensing();
        this.wiimote.activateSmoothing();
    }

    /**
     * カメラ
     */
    public final Player cameraPlayer;

    /**
     * 画面サイズ
     */
    public final Dimension dimension = new Dimension(640, 480);

    /**
     * カメラから取得した FrameGrabbingControl
     */
    public final FrameGrabbingControl grabbingControl;

    /**
     * メインフレーム
     */
    public final JFrame mainFrame;

    /**
     * wii
     */
    public final Wiimote wiimote;
}
